// pages/zhaoping/zhaoping.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

    xueshen: true,
    xingbie: true,
    nianji: true,
    txtlist: [],

    STUDENT_PHONE: '', //手机号
    USER_IDCARD: '', //身份证号
    POST_NAME: '', //姓名



    POST_SEX: '',
    POST_AGE: '',
    POST_QX: '',
    POST_ADD: '',
    shangwang: '',
    sbwngdian: true,
    wangdiany: true,



    modalHidden: true,
    canshu: '',
    USER_ASSETS_IDCARD: '',
    ad_img: '',
    PRIZE_ID: '',
    choujiang: true,
    openid: '',
    OPEN_ID: '',
    SHARE_OPEN_ID: '',












    wang_d: '', //地点
    city: [], //市
    district: [], //区
    business: '', //网点
    shi_k: true,
    qu_k: true,
    wang_k: true,
    tishi: true,

    L2code: '',
    L3code: '',

    L2name: '',
    L3name: '',
    L4name: '',

  },










  idcardblur: function (e) {
    let idcard = e.detail.value;
    let reg = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;

    if (reg.test(idcard) == false) {
      this.setData({
        USER_IDCARD: ''
      })
      wx.showToast({
        title: '身份证号码有误',
        icon: 'none',
        duration: 3000
      })



    } else {
      this.setData({
        USER_IDCARD: idcard
      })


    }

  },










  //验证手机号
  mobileInput(e) {
    let value = e.detail.value.replace(/\D/g, '')
    this.setData({
      mobile: value,
    })
    var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(19[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    if (this.data.mobile.length == 0) {
      wx.showToast({
        title: '输入的手机号为空，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        mobileFormat: false,
      })
    } else if (this.data.mobile.length < 11) {

      wx.showToast({
        title: '手机号长度有误，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        POST_PHONE: '',
        mobileFormat: false,
      })

    } else if (!myreg.test(this.data.mobile)) {
      wx.showToast({
        title: '手机号有误，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        POST_PHONE: '',
        mobileFormat: false,
      })

    } else {
      this.setData({
        mobileFormat: true,
      })
    }
  },




  bouut() {
    this.setData({
      openid: app.globalData.openid,
    })

    console.log(this.data.openid);
    // if (this.data.POST_SEX == "" ||this.data.POST_AGE == "" ||this.data.POST_SALARY == "" || this.data.POST_WORK == "" ||this.data.POST_NAME == "" || this.data.STUDENT_PHONE == ""|| this.data.POST_QX == ""|| this.data.POST_ADD == "") {
    if (  this.data.L2name == "" || this.data.L3name == "" || this.data.L4name == "") {
      wx.showToast({
        title: '请完善信息',
        icon: 'none',
        duration: 1500
      })

    } else {
      wx.request({
        url: app.globalData.interface+'/crossVersionOne/API2_1001_addQianYuanAssets',
        method: 'POST',
        data: {
          // USER_ASSETS_NAME: this.data.POST_NAME,
          // USER_COUPON_PHONE: this.data.STUDENT_PHONE,
          // USER_IDCARD: this.data.USER_IDCARD,




          BANK_ASSETS:this.data.EMPLOYEE_ID,
          USER_ADD: this.data.L2name + '_' + '_' + this.data.L3name + '_' + this.data.L4name,
          OPEN_ID: this.data.openid, //用户OPEN_ID
          session_key: this.data.session_key,
          OPEN_UUID: this.data.jiami,
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: res => {
          console.log(res.data);
          console.log(res);

          if (res.data.result == 'success') {
            wx.showModal({
              // title: '温馨提示',
              content: res.data.data,
              success: function (res) {
                if (res.confirm) { //这里是点击了确定以后   
                  console.log('用户点击确定')
                } else { //这里是点击了取消以后
                  console.log('用户点击取消')
                }
              }
            })
          } else {
            wx.showModal({
              // title: '温馨提示',
              content: res.data.data,
              success: function (res) {
                if (res.confirm) { //这里是点击了确定以后   
                  console.log('用户点击确定')
                } else { //这里是点击了取消以后
                  console.log('用户点击取消')
                }
              }
            })
          }
        }
      })
    }
  },










  // 地区数据
  region() {
    wx.request({
      url: app.globalData.interface+'/newVersion/API_2029_outletPush',
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res.data.data);
        this.setData({
          city: res.data.data,
        })

      }
    })
  },


  but_shi() {
    this.setData({
      shi_k: false,

    })

    this.setData({
      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      openid: app.globalData.openid,
      session_key: app.globalData.session_key,
    });

    console.log(this.data.session_key);
  },

  but_xian() {
    if (this.data.L2code == '') {
      wx.showToast({
        title: '请先选择市',
        icon: 'error',
        duration: 2000
      })
    } else {
      this.setData({
        qu_k: false
      })
    }
  },

  but_w() {

    if (this.data.L2code == '') {
      wx.showToast({
        title: '请先选择区',
        icon: 'error',
        duration: 2000
      })
    } else {
      this.setData({
        wang_k: false
      })
    }

  },


  //市
  buttn_c(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.item.district);
    console.log(e.currentTarget.dataset.item.L2code);
    this.setData({
      district: e.currentTarget.dataset.item.district,
      L2code: e.currentTarget.dataset.item.L2code,
      L2name: e.currentTarget.dataset.item.L2name,
      shi_k: true,
      L3name: '',
      L4name: '',

    })

  },

  buttn_x(e) {
    console.log(e);


    this.setData({
      L3code: e.currentTarget.dataset.item.L3code,
      L3name: e.currentTarget.dataset.item.L3name,
      qu_k: true,
      L4name: '',
    })
    this.Outlets()

  },


  buttn_w(e) {
    console.log(e);
    this.setData({
      L4name: e.currentTarget.dataset.item.L4name,
      EMPLOYEE_ID: e.currentTarget.dataset.item.EMPLOYEE_ID,
    
      wang_k: true
    })


  


  },

  //网点
  Outlets() {
    wx.request({
      url: app.globalData.interface+'/newVersion/API_2027_outletList',
      method: 'POST',
      data: {
        L2code: this.data.L2code,
        L3code: this.data.L3code
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res);
        console.log(res.data.data);
        this.setData({
          business: res.data.data
        })

      }
    })
  },










 





















  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(e) {
    this.setData({
      openid: app.globalData.openid,
      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,
      CUSTOMER_ID: app.globalData.CUSTOMER_ID,
    });


 
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {








    this.region()


  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {}


})